package com.gitee.wsl.android.ui.spannable.span

import android.annotation.SuppressLint
import android.graphics.Canvas
import android.graphics.Paint
import android.text.Layout
import android.text.style.QuoteSpan

/**
 * Configurable properties.
 */
@SuppressLint("ParcelCreator")
class MyQuoteSpan @JvmOverloads constructor(
    protected var mColor: Int,
    protected var mGapWidth: Int = 2,
    protected var mStripeWidth: Int = 2
) : QuoteSpan(mColor) {
    /**
     * @param mColor color of stripe
     * @param mGapWidth in pixels
     */
    override fun getLeadingMargin(first: Boolean): Int {
        return mGapWidth
    }

    override fun drawLeadingMargin(
        c: Canvas, p: Paint, x: Int, dir: Int,
        top: Int, baseline: Int, bottom: Int,
        text: CharSequence, start: Int, end: Int,
        first: Boolean, layout: Layout
    ) {
        val style = p.style
        val color = p.color
        p.style = Paint.Style.FILL
        p.color = mColor
        c.drawRect(
            x.toFloat(),
            top.toFloat(),
            (x + dir * mStripeWidth).toFloat(),
            bottom.toFloat(),
            p
        )
        p.style = style
        p.color = color
    }
}